package com.sgb.kjwl.viewmodel.vehicleManagement;

import androidx.databinding.ObservableField;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.api.NewAPIManager;
import com.sgb.kjwl.model.entity.DriverInfo;
import com.sgb.kjwl.repository.HomeRepertory;
import com.sgb.kjwl.view.ui.activity.vehicleManagement.DriverInfoActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class DriverInfoAtModel extends BaseViewModel {
    public ObservableField<DriverInfo> detailEntity = new ObservableField<>(new DriverInfo());
    DriverInfoActivity driverInfoActivity;
    HomeRepertory repertory;

    public DriverInfoAtModel(DriverInfoActivity driverInfoActivity, HomeRepertory repertory) {
        this.driverInfoActivity = driverInfoActivity;
        this.repertory = repertory;
    }

    public void getInfo(){
        DialogHelper.showProgressDialog(driverInfoActivity, null, "加载中", 0, true, null).setCanceledOnTouchOutside(false);
        NewAPIManager.getInstance().getLogisticsAPI().getDriverInfo().enqueue(new Callback<BaseEntity<DriverInfo>>() {
            @Override
            public void onResponse(Call<BaseEntity<DriverInfo>> call, Response<BaseEntity<DriverInfo>> response) {
                DialogHelper.dismissProgressDialog();

                if (response.body() == null) return;

                if (response.body().getState().equals("ok")) {
                    detailEntity.set(response.body().getData());
                    driverInfoActivity.setDataInfo(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<DriverInfo>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });

    }

}
